package com.clickpaas.materialsprocurement.common.Interceptor;

import com.bizcloud.ipaas.t0ba0ba6afb694026b6b4e4e048af2b43.d20210202135416.auth.extension.AuthConfig;
import com.clickpaas.materialsprocurement.config.AutoLoadConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * @company <上海爱湃斯科技有限公司>
 * @email <zhihui.peng@clickpaas.com>
 * @author huiye
 * @decription: 拦截器验证用户登陆token
 * @date 2020/12/27 1:22 下午
 */
@Slf4j
public class InitVerInterceptor extends HandlerInterceptorAdapter {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String token = request.getHeader("tg-token");
        init(AutoLoadConfig.ACCESSKEY_ID,AutoLoadConfig.ACCESSKEY_SECRET,token);
        return true;
    }

    public void init( String accesskeyId, String accesskeySecret, String token) {
        AuthConfig authConfig = new AuthConfig(accesskeyId, accesskeySecret, token);
        authConfig.initAuth();
    }

}
